/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: error_domain.h
 *
 * Purpose: This section describes the dog::core::ErrorDomain type that 
 *          constitutes a base class for error domain implementations
 *
 * Developer:
 *   wen.gu , 2022-08-06
 *
 * TODO:
 *
 ***************************************************************************/

#ifndef __DOG_CORE_ERROR_DOMAIN_H__
#define __DOG_CORE_ERROR_DOMAIN_H__
/******************************************************************************
 **    INCLUDES
 ******************************************************************************/

#include <cstdint>

/******************************************************************************
 **    MACROS
 ******************************************************************************/

#ifndef ERR_DOMAIN_CASE
#define ERR_DOMAIN_CASE(err) case err: return #err
#endif

#ifndef ERR_DOMAIN_CASE_DEFAULT
#define ERR_DOMAIN_CASE_DEFAULT default: return "Unknown Error"
#endif
/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace dog {
namespace core {
/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
class ErrorCode;

class ErrorDomain {
public:
    using IdType = std::uint64_t;
    using CodeType = std::int32_t;
    using SupportDataType = std::int32_t; //IMPLEMENTATION_DEFINED; //todo defined it.
public:
    explicit constexpr ErrorDomain(IdType id) noexcept  :mId(id) {
        /** todo something */
    }

    virtual ~ErrorDomain() { };

public: /** for compare */
    constexpr bool operator== (ErrorDomain const& other) const noexcept {
        return other.mId == mId;
    }

    constexpr bool operator!= (ErrorDomain const& other) const noexcept {
        return (mId != other.mId);
    }

public: 
    constexpr IdType Id() const noexcept{ return mId; }

public:
    virtual char const* Name() const noexcept = 0;
    virtual char const* Message(CodeType errorCode) const noexcept = 0;
    virtual void ThrowAsException(ErrorCode const& errorCode) const noexcept(false) = 0;
private:
    ErrorDomain(ErrorDomain const&) = delete;
    ErrorDomain(ErrorDomain&&) = delete;
    ErrorDomain& operator= (ErrorDomain const&) = delete;
    ErrorDomain& operator= (ErrorDomain&&) = delete;

private:
    IdType mId = 0;
};

} /** namespace core */
} /** namespace dog */

#endif /** !__DOG_CORE_ERROR_DOMAIN_H__ */

